package com.iams.manage.controller;

import com.iams.common.annotation.Log;
import com.iams.common.core.controller.BaseController;
import com.iams.common.core.domain.AjaxResult;
import com.iams.common.core.page.TableDataInfo;
import com.iams.common.enums.BusinessType;
import com.iams.common.utils.SecurityUtils;
import com.iams.common.utils.poi.ExcelUtil;
import com.iams.manage.domain.ArchiveDestroyApproval;
import com.iams.manage.service.IArchiveDestroyApprovalService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 档案销毁Controller
 * 
 * @author LiuTao
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/manage/ArchiveDestroyRecord")
public class ArchiveDestroyApprovalController extends BaseController
{
    @Autowired
    private IArchiveDestroyApprovalService archiveDestroyApprovalService;

    /**
     * 查询档案销毁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveDestroyApproval archiveDestroyApproval)
    {
        if(!SecurityUtils.hasRole("admin")) {
            archiveDestroyApproval.setUserId(SecurityUtils.getLoginUser().getUserId());
        }
        startPage();
        List<ArchiveDestroyApproval> list = archiveDestroyApprovalService.selectArchiveDestroyApprovalList(archiveDestroyApproval);
        return getDataTable(list);
    }

    /**
     * 导出档案销毁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:export')")
    @Log(title = "档案销毁", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveDestroyApproval archiveDestroyApproval)
    {
        List<ArchiveDestroyApproval> list = archiveDestroyApprovalService.selectArchiveDestroyApprovalList(archiveDestroyApproval);
        ExcelUtil<ArchiveDestroyApproval> util = new ExcelUtil<ArchiveDestroyApproval>(ArchiveDestroyApproval.class);
        util.exportExcel(response, list, "档案销毁数据");
    }

    /**
     * 获取档案销毁详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(archiveDestroyApprovalService.selectArchiveDestroyApprovalById(id));
    }

    /**
     * 新增档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:add')")
    @Log(title = "档案销毁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveDestroyApproval archiveDestroyApproval)
    {
        return toAjax(archiveDestroyApprovalService.insertArchiveDestroyApproval(archiveDestroyApproval));
    }

    /**
     * 修改档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:edit')")
    @Log(title = "档案销毁", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveDestroyApproval archiveDestroyApproval)
    {
        return toAjax(archiveDestroyApprovalService.updateArchiveDestroyApproval(archiveDestroyApproval));
    }

    /**
     * 删除档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:remove')")
    @Log(title = "档案销毁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(archiveDestroyApprovalService.deleteArchiveDestroyApprovalByIds(ids));
    }
}
